﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import flash.display.*;
    import org.aswing.plaf.*;
    import org.aswing.event.*;
    import org.aswing.util.*;
    import org.aswing.error.*;

    public class AbstractButton extends Component {

        public static const CENTER:int = 0;
        public static const TOP:int = 1;
        public static const LEFT:int = 2;
        public static const BOTTOM:int = 3;
        public static const RIGHT:int = 4;
        public static const HORIZONTAL:int = 0;
        public static const VERTICAL:int = 1;

        private var model:ButtonModel;
        private var text:String;
        private var displayText:String;
        private var mnemonic:int;
        private var mnemonicIndex:int;
        private var mnemonicEnabled:Boolean;
        private var margin:Insets;
        private var defaultMargin:Insets;
        private var defaultIcon:Icon;
        private var pressedIcon:Icon;
        private var disabledIcon:Icon;
        private var selectedIcon:Icon;
        private var disabledSelectedIcon:Icon;
        private var rolloverIcon:Icon;
        private var rolloverSelectedIcon:Icon;
        private var rolloverEnabled:Boolean;
        private var verticalAlignment:int;
        private var horizontalAlignment:int;
        private var verticalTextPosition:int;
        private var horizontalTextPosition:int;
        private var iconTextGap:int;
        private var shiftOffset:int = 0;
        private var shiftOffsetSet:Boolean = false;
        private var textFilters:Array;
        private var rootPane:JRootPane;

        public function AbstractButton(_arg1:String="", _arg2:Icon=null){
            setName("AbstractButton");
            this.rolloverEnabled = true;
            this.verticalAlignment = CENTER;
            this.horizontalAlignment = CENTER;
            this.verticalTextPosition = CENTER;
            this.horizontalTextPosition = RIGHT;
            this.textFilters = new ArrayUIResource();
            this.iconTextGap = 2;
            this.mnemonicEnabled = true;
            this.text = _arg1;
            this.analyzeMnemonic();
            this.defaultIcon = _arg2;
            this.initSelfHandlers();
            this.updateUI();
            this.installIcon(this.defaultIcon);
        }
        public function getModel():ButtonModel{
            return (this.model);
        }
        public function setModel(_arg1:ButtonModel):void{
            var _local2:ButtonModel = this.getModel();
            if (_local2 != null){
                _local2.removeActionListener(this.__modelActionListener);
                _local2.removeStateListener(this.__modelStateListener);
                _local2.removeSelectionListener(this.__modelSelectionListener);
            };
            this.model = _arg1;
            if (_arg1 != null){
                _arg1.addActionListener(this.__modelActionListener);
                _arg1.addStateListener(this.__modelStateListener);
                _arg1.addSelectionListener(this.__modelSelectionListener);
            };
            if (_arg1 != _local2){
                revalidate();
                repaint();
            };
        }
        override public function updateUI():void{
            throw (new ImpMissError());
        }
        public function doClick():void{
            dispatchEvent(new MouseEvent(MouseEvent.ROLL_OVER, true, false, 0, 0));
            dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false, 0, 0));
            if (isOnStage()){
                dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP, true, false, 0, 0));
            } else {
                dispatchEvent(new ReleaseEvent(ReleaseEvent.RELEASE, this, false, new MouseEvent(MouseEvent.MOUSE_UP)));
            };
            dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false, 0, 0));
            dispatchEvent(new MouseEvent(MouseEvent.ROLL_OUT, true, false, 0, 0));
        }
        public function addActionListener(_arg1:Function, _arg2:int=0, _arg3:Boolean=false):void{
            addEventListener(AWEvent.ACT, _arg1, false, _arg2, _arg3);
        }
        public function removeActionListener(_arg1:Function):void{
            removeEventListener(AWEvent.ACT, _arg1);
        }
        public function addSelectionListener(_arg1:Function, _arg2:int=0, _arg3:Boolean=false):void{
            addEventListener(InteractiveEvent.SELECTION_CHANGED, _arg1, false, _arg2);
        }
        public function removeSelectionListener(_arg1:Function):void{
            removeEventListener(InteractiveEvent.SELECTION_CHANGED, _arg1);
        }
        public function addStateListener(_arg1:Function, _arg2:int=0, _arg3:Boolean=false):void{
            addEventListener(InteractiveEvent.STATE_CHANGED, _arg1, false, _arg2);
        }
        public function removeStateListener(_arg1:Function):void{
            removeEventListener(InteractiveEvent.STATE_CHANGED, _arg1);
        }
        override public function setEnabled(_arg1:Boolean):void{
            if (((!(_arg1)) && (this.model.isRollOver()))){
                this.model.setRollOver(false);
            };
            super.setEnabled(_arg1);
            this.model.setEnabled(_arg1);
        }
        public function isSelected():Boolean{
            return (this.model.isSelected());
        }
        public function setSelected(_arg1:Boolean):void{
            this.model.setSelected(_arg1);
        }
        public function setRollOverEnabled(_arg1:Boolean):void{
            if (this.rolloverEnabled != _arg1){
                this.rolloverEnabled = _arg1;
                repaint();
            };
        }
        public function isRollOverEnabled():Boolean{
            return (this.rolloverEnabled);
        }
        public function setMargin(_arg1:Insets):void{
            if ((_arg1 is UIResource)){
                this.defaultMargin = _arg1;
            };
            if ((((_arg1 == null)) && (!((this.defaultMargin == null))))){
                _arg1 = this.defaultMargin;
            };
            var _local2:Insets = this.margin;
            this.margin = _arg1;
            if ((((_local2 == null)) || (!(_arg1.equals(_local2))))){
                revalidate();
                repaint();
            };
        }
        public function getMargin():Insets{
            var _local1:Insets = this.margin;
            if (this.margin == null){
                _local1 = this.defaultMargin;
            };
            if (_local1 == null){
                return (new InsetsUIResource());
            };
            if ((_local1 is UIResource)){
                return (new InsetsUIResource(_local1.top, _local1.left, _local1.bottom, _local1.right));
            };
            return (new Insets(_local1.top, _local1.left, _local1.bottom, _local1.right));
        }
        public function setTextFilters(_arg1:Array):void{
            this.textFilters = _arg1;
            repaint();
        }
        public function getTextFilters():Array{
            return (this.textFilters);
        }
        public function wrapSimpleButton(_arg1:SimpleButton):AbstractButton{
            this.setShiftOffset(0);
            this.setIcon(new SimpleButtonIconToggle(_arg1));
            setBorder(null);
            this.setMargin(new Insets());
            setBackgroundDecorator(null);
            setOpaque(false);
            return (this);
        }
        public function setText(_arg1:String):void{
            if (this.text != _arg1){
                this.text = _arg1;
                this.analyzeMnemonic();
                repaint();
                invalidate();
            };
        }
        public function setMnemonicEnabled(_arg1:Boolean):void{
            if (this.mnemonicEnabled != _arg1){
                this.mnemonicEnabled = _arg1;
                this.analyzeMnemonic();
            };
        }
        public function isMnemonicEnabled():Boolean{
            return (this.mnemonicEnabled);
        }
        private function analyzeMnemonic():void{
            this.displayText = this.text;
            this.mnemonic = -1;
            this.mnemonicIndex = -1;
            if (this.text == null){
                return;
            };
            if (!this.mnemonicEnabled){
                return;
            };
            var _local1:int = this.text.indexOf("&");
            var _local2 = "";
            var _local3:Boolean;
            while (_local1 >= 0) {
                if ((_local1 + 1) < this.text.length){
                    _local2 = this.text.charAt((_local1 + 1));
                    if (StringUtils.isLetter(_local2)){
                        _local3 = true;
                        break;
                    };
                } else {
                    break;
                };
                _local1 = this.text.indexOf("&", (_local1 + 1));
            };
            if (_local3){
                this.displayText = (this.text.substring(0, _local1) + this.text.substring((_local1 + 1)));
                this.mnemonic = _local2.toUpperCase().charCodeAt(0);
                this.mnemonicIndex = _local1;
            };
        }
        public function getText():String{
            return (this.text);
        }
        public function getDisplayText():String{
            return (this.displayText);
        }
        public function getMnemonicIndex():int{
            return (this.mnemonicIndex);
        }
        public function getMnemonic():int{
            return (this.mnemonic);
        }
        protected function installIcon(_arg1:Icon):void{
            if (((!((_arg1 == null))) && (!((_arg1.getDisplay(this) == null))))){
                addChild(_arg1.getDisplay(this));
            };
        }
        protected function uninstallIcon(_arg1:Icon):void{
            var _local2:DisplayObject = ((_arg1 == null)) ? null : _arg1.getDisplay(this);
            if (((!((_local2 == null))) && (isChild(_local2)))){
                removeChild(_arg1.getDisplay(this));
            };
        }
        public function setIcon(_arg1:Icon):void{
            if (this.defaultIcon != _arg1){
                this.uninstallIcon(this.defaultIcon);
                this.defaultIcon = _arg1;
                this.installIcon(_arg1);
                repaint();
                invalidate();
            };
        }
        public function getIcon():Icon{
            return (this.defaultIcon);
        }
        public function getPressedIcon():Icon{
            return (this.pressedIcon);
        }
        public function setPressedIcon(_arg1:Icon):void{
            var _local2:Icon = this.pressedIcon;
            this.pressedIcon = _arg1;
            if (_arg1 != _local2){
                this.uninstallIcon(_local2);
                this.installIcon(_arg1);
                repaint();
            };
        }
        public function getSelectedIcon():Icon{
            return (this.selectedIcon);
        }
        public function setSelectedIcon(_arg1:Icon):void{
            var _local2:Icon = this.selectedIcon;
            this.selectedIcon = _arg1;
            if (_arg1 != _local2){
                this.uninstallIcon(_local2);
                this.installIcon(_arg1);
                repaint();
            };
        }
        public function getRollOverIcon():Icon{
            return (this.rolloverIcon);
        }
        public function setRollOverIcon(_arg1:Icon):void{
            var _local2:Icon = this.rolloverIcon;
            this.rolloverIcon = _arg1;
            this.setRollOverEnabled(true);
            if (_arg1 != _local2){
                this.uninstallIcon(_local2);
                this.installIcon(_arg1);
                repaint();
            };
        }
        public function getRollOverSelectedIcon():Icon{
            return (this.rolloverSelectedIcon);
        }
        public function setRollOverSelectedIcon(_arg1:Icon):void{
            var _local2:Icon = this.rolloverSelectedIcon;
            this.rolloverSelectedIcon = _arg1;
            this.setRollOverEnabled(true);
            if (_arg1 != _local2){
                this.uninstallIcon(_local2);
                this.installIcon(_arg1);
                repaint();
            };
        }
        public function getDisabledIcon():Icon{
            if (this.disabledIcon == null){
                if (this.defaultIcon != null){
                    return (this.defaultIcon);
                };
            };
            return (this.disabledIcon);
        }
        public function setDisabledIcon(_arg1:Icon):void{
            var _local2:Icon = this.disabledIcon;
            this.disabledIcon = _arg1;
            if (_arg1 != _local2){
                this.uninstallIcon(_local2);
                this.installIcon(_arg1);
                repaint();
            };
        }
        public function getDisabledSelectedIcon():Icon{
            if (this.disabledSelectedIcon == null){
                if (this.selectedIcon != null){
                } else {
                    return (this.getDisabledIcon());
                };
            };
            return (this.disabledSelectedIcon);
        }
        public function setDisabledSelectedIcon(_arg1:Icon):void{
            var _local2:Icon = this.disabledSelectedIcon;
            this.disabledSelectedIcon = _arg1;
            if (_arg1 != _local2){
                this.uninstallIcon(_local2);
                this.installIcon(_arg1);
                repaint();
                revalidate();
            };
        }
        public function getVerticalAlignment():int{
            return (this.verticalAlignment);
        }
        public function setVerticalAlignment(_arg1:int):void{
            if (_arg1 == this.verticalAlignment){
                return;
            };
            this.verticalAlignment = _arg1;
            repaint();
        }
        public function getHorizontalAlignment():int{
            return (this.horizontalAlignment);
        }
        public function setHorizontalAlignment(_arg1:int):void{
            if (_arg1 == this.horizontalAlignment){
                return;
            };
            this.horizontalAlignment = _arg1;
            repaint();
        }
        public function getVerticalTextPosition():int{
            return (this.verticalTextPosition);
        }
        public function setVerticalTextPosition(_arg1:int):void{
            if (_arg1 == this.verticalTextPosition){
                return;
            };
            this.verticalTextPosition = _arg1;
            repaint();
            revalidate();
        }
        public function getHorizontalTextPosition():int{
            return (this.horizontalTextPosition);
        }
        public function setHorizontalTextPosition(_arg1:int):void{
            if (_arg1 == this.horizontalTextPosition){
                return;
            };
            this.horizontalTextPosition = _arg1;
            repaint();
            revalidate();
        }
        public function getIconTextGap():int{
            return (this.iconTextGap);
        }
        public function setIconTextGap(_arg1:int):void{
            var _local2:int = this.iconTextGap;
            this.iconTextGap = _arg1;
            if (_arg1 != _local2){
                revalidate();
                repaint();
            };
        }
        public function getShiftOffset():int{
            return (this.shiftOffset);
        }
        public function setShiftOffset(_arg1:int):void{
            var _local2:int = this.shiftOffset;
            this.shiftOffset = _arg1;
            this.setShiftOffsetSet(true);
            if (_arg1 != _local2){
                revalidate();
                repaint();
            };
        }
        public function isShiftOffsetSet():Boolean{
            return (this.shiftOffsetSet);
        }
        public function setShiftOffsetSet(_arg1:Boolean):void{
            this.shiftOffsetSet = _arg1;
        }
        private function initSelfHandlers():void{
            addEventListener(MouseEvent.ROLL_OUT, this.__rollOutListener);
            addEventListener(MouseEvent.ROLL_OVER, this.__rollOverListener);
            addEventListener(MouseEvent.MOUSE_DOWN, this.__mouseDownListener);
            addEventListener(ReleaseEvent.RELEASE, this.__mouseReleaseListener);
            addEventListener(Event.ADDED_TO_STAGE, this.__addedToStage);
            addEventListener(Event.REMOVED_FROM_STAGE, this.__removedFromStage);
        }
        private function __addedToStage(_arg1:Event):void{
            this.rootPane = getRootPaneAncestor();
            if (this.rootPane != null){
                this.rootPane.registerMnemonic(this);
            };
        }
        private function __removedFromStage(_arg1:Event):void{
            if (this.rootPane != null){
                this.rootPane.unregisterMnemonic(this);
                this.rootPane = null;
            };
        }
        private function __rollOverListener(_arg1:MouseEvent):void{
            var _local2:ButtonModel = this.getModel();
            if (this.isRollOverEnabled()){
                if (((_local2.isPressed()) || (!(_arg1.buttonDown)))){
                    _local2.setRollOver(true);
                };
            };
            if (_local2.isPressed()){
                _local2.setArmed(true);
            };
        }
        private function __rollOutListener(_arg1:MouseEvent):void{
            var _local2:ButtonModel = this.getModel();
            if (this.isRollOverEnabled()){
                if (!_local2.isPressed()){
                    _local2.setRollOver(false);
                };
            };
            _local2.setArmed(false);
        }
        private function __mouseDownListener(_arg1:Event):void{
            this.getModel().setArmed(true);
            this.getModel().setPressed(true);
        }
        private function __mouseReleaseListener(_arg1:Event):void{
            this.getModel().setPressed(false);
            this.getModel().setArmed(false);
            if (((this.isRollOverEnabled()) && (!(hitTestMouse())))){
                this.getModel().setRollOver(false);
            };
        }
        private function __modelActionListener(_arg1:AWEvent):void{
            dispatchEvent(new AWEvent(AWEvent.ACT));
        }
        private function __modelStateListener(_arg1:AWEvent):void{
            dispatchEvent(new InteractiveEvent(InteractiveEvent.STATE_CHANGED));
        }
        private function __modelSelectionListener(_arg1:AWEvent):void{
            dispatchEvent(new InteractiveEvent(InteractiveEvent.SELECTION_CHANGED));
        }

    }
}//package org.aswing 
